package com.junction.thread;

import com.junction.util.ScreenCapture;
import com.junction.pojo.TaskPojo;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ScreenCaptureThread {
    public static class MyRunnable implements Runnable {
        // 创建线程池
        public static ExecutorService es = Executors.newCachedThreadPool();
        private Thread nowThread;

        private TaskPojo taskPojo;

        public MyRunnable(TaskPojo taskPojo) {
            this.taskPojo = taskPojo;
        }

        // 中断线程
        public void setInterrupted() {
            nowThread.interrupt();
        }

        @Override
        public void run() {
            try {

                ScreenCapture.captureScreen(taskPojo);

            } catch (Exception e) {
                System.err.println(
                        "当前线程：" + Thread.currentThread().getName() + " 当前任务：" + taskPojo.getFilePath() + "停止...");
                e.printStackTrace();
            }
        }
    }
}
